//
//  aaaViewController.m
//  Frame
//
//  Created by 这是工作本 on 16/1/5.
//  Copyright © 2016年 这是工作本. All rights reserved.
//

#import "aaaViewController.h"

@interface aaaViewController ()<UIGestureRecognizerDelegate, UITextFieldDelegate>
@property (nonatomic, retain) UIButton *weixin;
@property (nonatomic, retain) UIButton *qq;
@property (nonatomic, retain) UIButton *weibo;

@property (nonatomic, retain) UITextField *text;

@property (nonatomic, retain) UITextField *passText;
@end

@implementation aaaViewController


- (void)viewWillAppear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = YES;
    self.navigationController.navigationBarHidden = NO;
    [self.text resignFirstResponder];
    [self.passText resignFirstResponder];


}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
      self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:29 / 255.0 green:127 / 255.0  blue:140 / 255.0  alpha:1.0];
    self.navigationItem.title = @"登陆";
    //隐藏自动返回
    self.navigationItem.hidesBackButton = YES;
    
    //返回按钮
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"but_an.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]style:UIBarButtonItemStylePlain target:self action:@selector(leftBarButtonAction:)];
    
    
    //设置title颜色
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithRed:255 / 255.0 green:255 / 255.0 blue:255 / 255.0 alpha:1.0],NSForegroundColorAttributeName,nil]];
    
    
    
    //注册
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"注册" style:UIBarButtonItemStylePlain target:self action:@selector(right)];
    
    self.navigationItem.rightBarButtonItem.tintColor = [UIColor colorWithRed:255 / 255.0 green:255 / 255.0 blue:255 / 255.0 alpha:1.0];
    
    
    UIImageView *view = [[UIImageView alloc] initWithFrame:CGRectMake(20 * ScreenWidth, 40 * ScreenHeigth, 60 * ScreenWidth, 45 * ScreenHeigth)];
    view.image = [UIImage imageNamed:@"dr_sr_rec05.png"];
    [self.view addSubview:view];

    
    
    //手机
    UILabel *la = [[UILabel alloc] initWithFrame:CGRectMake(20 * ScreenWidth, 40 * ScreenHeigth, 60 * ScreenWidth, 45 * ScreenHeigth)];
    la.text = @"+86";
    la.textColor = [UIColor colorWithRed:255 / 255.0 green:255 / 255.0 blue:255 / 255.0 alpha:1.0];
    la.textAlignment = NSTextAlignmentCenter;
    la.layer.cornerRadius = 10 * ScreenWidth;
    la.layer.masksToBounds = YES;
    [self.view addSubview:la];
    
    UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(la.frame.origin.x + 60 * ScreenWidth, la.frame.origin.y, [UIScreen mainScreen].bounds.size.width - 100 * ScreenWidth, 45 * ScreenHeigth)];
    imageV.image = [UIImage imageNamed:@"图层-12@2x.png"];
    [self.view addSubview:imageV];

    
    self.text = [[UITextField alloc] initWithFrame:CGRectMake(la.frame.origin.x + la.frame.size.width, la.frame.origin.y, [UIScreen mainScreen].bounds.size.width - 100 * ScreenWidth, 45 * ScreenHeigth)];
    self.text.clearButtonMode = UITextFieldViewModeAlways;
    self.text.clearsOnBeginEditing = YES;
    self.text.delegate = self;
    self.text.textColor = [UIColor colorWithRed:100 / 255.0 green:100 / 255.0 blue:100 / 255.0 alpha:1.0];
    self.text.keyboardType = UIKeyboardTypePhonePad;
    self.text.placeholder = @"手机号码";
    [self.view addSubview:self.text];
 
    //密码
    self.passText = [[UITextField alloc] initWithFrame:CGRectMake(la.frame.origin.x, self.text.frame.origin.y + self.text.frame.size.height + 20 * ScreenHeigth, self.text.frame.size.width + la.frame.size.width, self.text.frame.size.height)];
    //字体靠左
    self.passText.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    self.passText.placeholder = @"密码";
    self.passText.layer.cornerRadius = 10 * ScreenWidth;
    self.passText.textColor = [UIColor colorWithRed:100 / 255.0 green:100 / 255.0 blue:100 / 255.0 alpha:1.0];

    self.passText.layer.masksToBounds = YES;
    //开始编辑清除
    self.passText.clearsOnBeginEditing = YES;
    //设置一次性清除
    self.passText.clearButtonMode = UITextFieldViewModeAlways;
    self.passText.backgroundColor = [UIColor colorWithRed:243 / 255.0 green:243 / 255.0 blue:243 / 255.0 alpha:1.0];
    self.passText.secureTextEntry = YES;
    [self.view addSubview:self.passText];
    //设置字体距离左边框的距离
    self.passText.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 40 * ScreenWidth, 0)];
    self.passText.leftViewMode = UITextFieldViewModeAlways;
    
    //图标
    UIImageView *pass = [[UIImageView alloc] initWithFrame:CGRectMake(la.frame.origin.x + 10 * ScreenWidth, self.text.frame.origin.y + self.text.frame.size.height + 32 * ScreenHeigth, 20 * ScreenWidth, 20 * ScreenHeigth)];
    pass.image = [UIImage imageNamed:@"形状-2@2x.png"];
    [self.view addSubview:pass];
    
    
    //登陆
    UILabel *login = [[UILabel alloc] initWithFrame:CGRectMake(self.passText.frame.origin.x, self.passText.frame.origin.y + self.passText.frame.size.height + 30 * ScreenHeigth, self.passText.frame.size.width, self.passText.frame.size.height)];
    login.text = @"登陆";
    login.textColor = [UIColor colorWithRed:255 / 255.0 green:255 / 255.0 blue:255 / 255.0 alpha:1.0];
    login.layer.cornerRadius = 10 * ScreenWidth;
    login.layer.masksToBounds = YES;
    login.textAlignment = NSTextAlignmentCenter;
    login.backgroundColor = [UIColor colorWithRed:29 / 255.0 green:127 / 255.0 blue:140 / 255.0 alpha:1.0];
    [self.view addSubview:login];
    
    
    
    //忘记密码
    UIButton *foget = [UIButton buttonWithType:UIButtonTypeCustom];
    foget.frame = CGRectMake(login.frame.origin.x, login.frame.origin.y + login.frame.size.height + 15 * ScreenHeigth, 60 * ScreenWidth, 15 * ScreenHeigth);
    [foget setTitleColor:[UIColor colorWithRed:30 / 255.0 green:30 / 255.0 blue:30 / 255.0 alpha:1.0] forState:UIControlStateNormal];
    foget.font = [UIFont systemFontOfSize:15.0 * ScreenWidth];
    [foget setTitle:@"忘记密码" forState:UIControlStateNormal];
    [foget addTarget:self action:@selector(forget) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:foget];

    
    
    
    UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(0, login.frame.origin.y + login.frame.size.height + 85 * ScreenHeigth, [UIScreen mainScreen].bounds.size.width, 20 * ScreenHeigth)];
    image.image = [UIImage imageNamed:@"333@2x.png"];
    [self.view addSubview:image];
    
    
    //微信登陆
    
    self.weixin = [UIButton buttonWithType:UIButtonTypeCustom];
    self.weixin.frame = CGRectMake(([UIScreen mainScreen].bounds.size.width - 80) / 3, image.frame.origin.y + image.frame.size.height + 71 * ScreenHeigth, 40 * ScreenWidth, 40 * ScreenHeigth);
    self.weixin.layer.cornerRadius = 20 * ScreenWidth;
    self.weixin.layer.masksToBounds = YES;
    [self.weixin setImage:[UIImage imageNamed:@"图层-8@2x.png"] forState:UIControlStateNormal];
    [self.weixin addTarget:self action:@selector(RegisterAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.weixin];
    
    //qq
    
    self.qq = [UIButton buttonWithType:UIButtonTypeCustom];
    self.qq.frame = CGRectMake(self.weixin.frame.origin.x + self.weixin.frame.size.width + ([UIScreen mainScreen].bounds.size.width - 80) / 3, self.weixin.frame.origin.y, 40 * ScreenWidth, 40 * ScreenHeigth);
    self.qq.layer.cornerRadius = 20 * ScreenWidth;
    self.qq.layer.masksToBounds = YES;
    [self.qq setImage:[UIImage imageNamed:@"图层-2@2x.png"] forState:UIControlStateNormal];
    [self.qq addTarget:self action:@selector(RegisterAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.qq];

    
    
    //微博
    
//    self.weibo = [UIButton buttonWithType:UIButtonTypeCustom];
//    self.weibo.frame = CGRectMake(self.qq.frame.origin.x + self.qq.frame.size.width + 54 * ScreenWidth, self.weixin.frame.origin.y, 40 * ScreenWidth, 40 * ScreenHeigth);
//    self.weibo.layer.cornerRadius = 20 * ScreenWidth;
//    self.weibo.layer.masksToBounds = YES;
//    [self.weibo setImage:[UIImage imageNamed:@"图层-9@2x.png"] forState:UIControlStateNormal];
//    [self.weibo addTarget:self action:@selector(RegisterAction:) forControlEvents:UIControlEventTouchUpInside];
//    [self.view addSubview:self.weibo];

    
    //点击空白回收键盘
    UITapGestureRecognizer *ges = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gesAction)];
    [self.view addGestureRecognizer:ges];
    
    //添加全屏右滑动手势
    id target = self.navigationController.interactivePopGestureRecognizer.delegate;
    // 创建全屏滑动手势，调用系统自带滑动手势的target的action方法
    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:target action:@selector(handleNavigationTransition:)];
    // 设置手势代理，拦截手势触发
    pan.delegate = self;
    // 给导航控制器的view添加全屏滑动手势
    [self.view addGestureRecognizer:pan];
    // 禁止使用系统自带的滑动手势
    self.navigationController.interactivePopGestureRecognizer.enabled = NO;

    
    
    
}

//限制手机输入十一位

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    
    
    NSString * toBeString = [textField.text stringByReplacingCharactersInRange:range withString:string]; //得到输入框的内容
    
    if (self.text == textField)  //判断是否时我们想要限定的那个输入框
    {
        if (toBeString.length > 11) { //如果输入框内容大于20则弹出警告
            
            
            return NO;
            
        }
    }

    
    return YES;
    
}




- (void)leftBarButtonAction:(UIBarButtonItem *)sender
{

    
    [self.navigationController popViewControllerAnimated:YES];
}


- (void)RegisterAction:(UIButton *)sender
{
    
}

- (void)forget
{
    
    
    
}
//注册界面
- (void)right
{
    bbbViewController *b = [[bbbViewController alloc] init];
    [self.navigationController pushViewController:b animated:YES];
    
}


//回收键盘
- (void)gesAction
{
    [self.text resignFirstResponder];
    [self.passText resignFirstResponder];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
  
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
